package com.util
{
	import flash.utils.ByteArray;
	import flash.utils.getDefinitionByName;
	import mx.controls.Alert;
	import mx.core.ByteArrayAsset;
	public class SwfUtil
	{

        public static const EFT_NAME_CAROTIC:String="carotic";
         public static const EFT_NAME_CRASH:String="crash";
         public static const EFT_NAME_REPAIR:String="repair";
          public static const EFT_NAME_STRICK:String="strick";
         public static const EFT_NAME_BLAST:String="blast";
		//item part
 
//		var c:Car_31000MC;
//		var c1:Car_31001MC;
//		var c2:Car_31002MC;
//		var c3:Car_31003MC;
//		var c4:Car_31004MC;
//		var c5:Car_31005MC;
//		var c6:Car_31006MC;
//		var c7:Car_31007MC;
         [Embed(source='assets/effect/carotic.bin', mimeType="application/octet-stream")]
         private static const Eft_carotic:Class;  
 
       [Embed(source='assets/effect/crash.bin', mimeType="application/octet-stream")]
         private static const Eft_crash:Class;  
       [Embed(source='assets/effect/repair.bin', mimeType="application/octet-stream")]
         private static const Eft_repair:Class;  
       [Embed(source='assets/effect/strick.bin', mimeType="application/octet-stream")]
         private static const Eft_strick:Class;    
         [Embed(source='assets/effect/blast.bin', mimeType="application/octet-stream")]
         private static const Eft_blast:Class;  
		public static function getEffectSwfStream(eftName:String):ByteArray{
		try{
 
	            var P:Class = getDefinitionByName("com.util.SwfUtil_Eft_"+eftName) as Class;
	           
	             var source:ByteArrayAsset = new P() as ByteArrayAsset;
	             var ret:ByteArray = new ByteArray();
	             
	             source.readBytes(ret);
	           
	             return ret;
          }catch(e:Error){
          	Alert.show(e.getStackTrace());
             	trace("error  happened when loading swf file in SwfUtil.getEffectSwfStream");
          }
           return null;
         }
 
 
       [Embed(source='assets/items/item/11050.bin', mimeType="application/octet-stream")]
       private static const Eft_item_11050:Class;     
		public static function getEffectAddedtemStream(id:int):ByteArray{
		try{
 
	            var P:Class = getDefinitionByName("com.util.SwfUtil_Eft_item_"+id) as Class;
	           
	             var source:ByteArrayAsset = new P() as ByteArrayAsset;
	             var ret:ByteArray = new ByteArray();
	             
	             source.readBytes(ret);
	           
	             return ret;
          }catch(e:Error){
          	Alert.show(e.getStackTrace());
             	trace("error  happened when loading swf file in SwfUtil.getEffectSwfStream");
          }
           return null;
         }
  
   
     
        [Embed(source='assets/items/car/31000.bin', mimeType="application/octet-stream")]
         private static const Car_31000:Class;
         
        [Embed(source='assets/items/car/31001.bin', mimeType="application/octet-stream")]
         private static const Car_31001:Class;
         
        [Embed(source='assets/items/car/32000.bin', mimeType="application/octet-stream")]
         private var Car_32000:Class;
         
        [Embed(source='assets/items/car/33000.bin', mimeType="application/octet-stream")]
         private static const Car_33000:Class;
         
        [Embed(source='assets/items/car/33001.bin', mimeType="application/octet-stream")]
         private static const Car_33001:Class;
         
        [Embed(source='assets/items/car/34000.bin', mimeType="application/octet-stream")]
         private static const Car_34000:Class;
         
        [Embed(source='assets/items/car/34001.bin', mimeType="application/octet-stream")]
         private static const Car_34001:Class;
         [Embed(source='assets/items/car/35000.bin', mimeType="application/octet-stream")]
         private static const Car_35000:Class;
        [Embed(source='assets/items/car/36000.bin', mimeType="application/octet-stream")]
         private static const Car_36000:Class; 
        [Embed(source='assets/items/car/37000.bin', mimeType="application/octet-stream")]
         private static const Car_37000:Class;  

 
 
         public static function getSwfStream(id:int):ByteArray{
		try{
		 
	            var P:Class = getDefinitionByName("com.util.SwfUtil_Car_"+id) as Class;
	           
	             var source:ByteArrayAsset = new P() as ByteArrayAsset;
//	             if(source==null){
//	             	P = getDefinitionByName("com.util.SwfUtil_Car_"+id) as Class;
//	                 source = new P() as ByteArrayAsset;
//	             }
	             var ret:ByteArray = new ByteArray();
	             source.readBytes(ret);
	           
	             return ret;
           }catch(e:Error){
          	trace("error   happened when loading swf file in SwfUtil.getSwfStream "+id);
          }
            return getDftSwfStream(31000);
         }
 
         private static function getDftSwfStream(id:int):ByteArray{
			try{
	            var P:Class = getDefinitionByName("com.util.SwfUtil_Car_31000") as Class;
	           
	             var source:ByteArrayAsset = new P() as ByteArrayAsset;
	             var ret:ByteArray = new ByteArray();
	             source.readBytes(ret);
	             return ret;
            }catch(e:Error){
            	trace("error  happened when loading swf file in SwfUtil.getDftSwfStream");
            }
            return null;
         }
	}
}